package com.example.myandroidtest;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myandroidtest.adapter.MenuAdapter;
import com.example.myandroidtest.bean.MenuBean;
import com.example.myandroidtest.databinding.ActivityMainBinding;
import com.example.myandroidtest.ui.bluetooth.BluetoothActivity;
import com.example.myandroidtest.ui.component.broadcast.BroadcastActivity;
import com.example.myandroidtest.ui.component.service.MusicActivity;
import com.example.myandroidtest.ui.image.ImageActivity;
import com.example.myandroidtest.ui.media.MediaCodecActivity;
import com.example.myandroidtest.ui.notification.NotificationActivity;
import com.example.myandroidtest.ui.retrofit.RetrofitActivity;
import com.example.myandroidtest.ui.surface.SurfaceActivity;
import com.example.myandroidtest.ui.thread.ThreadActivity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initView();
    }


    public List<MenuBean> getMenuList() {
        List<MenuBean> menuList = new ArrayList<>();
        menuList.add(new MenuBean("网络请求", RetrofitActivity.class));
        menuList.add(new MenuBean("图片加载", ImageActivity.class));
        menuList.add(new MenuBean("音乐播放", MusicActivity.class));
        menuList.add(new MenuBean("通知栏", NotificationActivity.class));
        menuList.add(new MenuBean("广播", BroadcastActivity.class));
        menuList.add(new MenuBean("线程", ThreadActivity.class));
        menuList.add(new MenuBean("Surface", SurfaceActivity.class));
        menuList.add(new MenuBean("蓝牙", BluetoothActivity.class));
        menuList.add(new MenuBean("MediaCodec", MediaCodecActivity.class));
        return menuList;
    }

    private void initView() {
        binding.toolbar.ivBack.setVisibility(View.GONE);
        binding.toolbar.tvTitle.setText("主页");

        RecyclerView recyclerView = binding.recyclerView;
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        List<MenuBean> menuList = getMenuList();
        recyclerView.setAdapter(new MenuAdapter(menuList, (holder, position) -> {
            MenuBean menu = menuList.get(position);
            if (menu.getActivity() == null) {
                Toast.makeText(this, "功能开发中,敬请期待", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent = new Intent(this, menu.getActivity());
            startActivity(intent);
        }));
    }
}